//封装存储工具
export const setStorage = (key, val) => {
  let value = ''
  if (typeof val === 'object') {
    //转换成字符串
    try {
      value = JSON.stringify(val)
    } catch (e) {
      //出现错误
      console.log(e)
    }
  } else {
    value = val
  }
  window.localStorage.setItem(key, value)
}

export const getStorage = (key) => {
  let res = window.localStorage.getItem(key)

  if (res) {
    //数组或者对象
    try {
      res = JSON.parse(res)
    } catch (e) {
      console.log(e)
    }
  }
  return res
}

export const removeStorage = (key) => {
  window.localStorage.removeItem(key)
}
